// index.ts
// 获取应用实例
const app = getApp<IAppOption>()
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Component({
  data: {
    motto: 'Hello World',
    fairyList: [],
    hasUserInfo: false,
    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
    active: 0,
  },
  methods: {
    // 事件处理函数
    menuChange(e: any) {
      // @ts-ignore
      this.setData({active: e.detail});
      switch (e.detail) {
         case 1:
          wx.navigateTo({
            url: `../hz/hz`
          })
          break;
      }
    },
    openfairyList(e: any) {
      wx.navigateTo({
        url: `../fairy/single?categoryId=${e.target.dataset.id}`
      })
    },
    fairyData() {
      wx.request({
        url:'https://wxapi.db101.cn/v1/fairy/all',
        success: (res) => {
          // @ts-ignore
          this.setData( {fairyList: res.data})
        }
      })
    }
  },
  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
      // @ts-ignore
      this.fairyData();
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  }
})
